package com.david.viewtest

import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import com.david.viewtest.widget.DiscoverBottomSheetCallback
import com.david.viewtest.widget.DragFloatWidget
import com.google.android.material.bottomsheet.BottomSheetBehavior

class AnimTestActivity:Activity() {
    lateinit var rightImg:ImageView
    lateinit var param: FrameLayout.LayoutParams
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_anim_test)
//        bottomSheet = findViewById(R.id.bottom_sheet)

        rightImg = findViewById(R.id.right_img)

        param = rightImg.layoutParams as FrameLayout.LayoutParams

        val floatWidget = DragFloatWidget(findViewById(R.id.bottom_sheet),  findViewById(R.id.title), this)
        floatWidget.bottomSheetCallback = object : DiscoverBottomSheetCallback {
            override fun onDragging(bottomSheet: View, eachDistance: Int, listHeight: Int,
                currentState: Int) {
                if(listHeight > (floatWidget.halfHeight + floatWidget.changeOffset)){
                    return
                } else if (listHeight < 50) {//高度小于50时不在设置
                    return
                }
                Log.e("event", "onDragging eachDistance:" + eachDistance + "   " + listHeight)
                param.bottomMargin = (listHeight + 10)
                rightImg.layoutParams = param
            }

            override fun onFling(bottomSheet: View, eachDistance: Int, listHeight: Int,
                newState: Int) {
                if(listHeight > (floatWidget.halfHeight + floatWidget.changeOffset)){
                    return
                } else if (listHeight < 50) {
                    return
                }
                Log.e("event", "onFling eachDistance:" + eachDistance + "  " + listHeight)
                param.bottomMargin = (listHeight + 10)
                rightImg.layoutParams = param
            }

            override fun onAnimEnd(bottomSheet: View, parentHeight: Int, newState: Int) {
            }

            override fun onHeaderClick(bottomSheet: View, listHeight: Int, currentState: Int) {
            }

        }
        rightImg.setOnClickListener {
            floatWidget.animToState(BottomSheetBehavior.STATE_HALF_EXPANDED)
        }
//        val title = findViewById<View>(R.id.title)


//        findViewById<View>(R.id.anim_img)
    }

}
